<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">   

    <ui:composition template="/templates/interna.xhtml">

	<ui:define name="breadcrumb">

	    <h:form>

		<p:breadCrumb>
		    <p:menuitem value="#{msg.principal}"/>
		    <p:menuitem value="#{msg.menuCadastros}"/>
		    <p:menuitem value="#{msg.subMenuCadastroDecreto}"/>
		    <p:menuitem value="#{msg.decretoCadastrar}" rendered="#{manterDecreto.decreto.id == null and !manterDecreto.isDetalhamento}"/>
		    <p:menuitem value="#{msg.decretoEditar}" rendered="#{manterDecreto.decreto.id != null and !manterDecreto.isDetalhamento}"/>
		    <p:menuitem value="#{msg.decretoDetalhar}" rendered="#{manterDecreto.isDetalhamento}"/>
		</p:breadCrumb>

	    </h:form>    

	</ui:define>

	<ui:define name="corpo">
	    
	    <script>
		function exibirConfirmacao(){
		    var exibirConfirmacao = #{manterDecreto.exibirConfirmacao};
		    window.alert(confirmacao);
		    if(exibirConfirmacao == true){
			pnConfirmaRemocaoReratificacao.show();
		    }
		}
	    </script>

	    <h:form id="fManterDecreto" >
		
		<p:fieldset id="fsDadosPrincipais" toggleSpeed="1" legend="#{msg.decretoDadosDecreto}">
		    <h:panelGrid columns="6">
			<h:panelGrid columns="1">
			    <p:outputLabel for="itNumeroDecreto" value="#{msg.decretoNumeroDecreto}"/>
			    <p:inputText id="itNumeroDecreto" size="20" maxlength="10" value="#{manterDecreto.decreto.numero}" required="true" requiredMessage="#{msg.decretoNumeroDecreto}: #{msg.campo_obrigatorio}"
					 disabled="#{manterDecreto.isDetalhamento}"/>
			</h:panelGrid>
			<h:panelGrid columns="1">
			    <p:outputLabel for="itDataDecreto" value="#{msg.decretoDataDecreto}"/>
			    <p:calendar id="itDataDecreto"
					value="#{manterDecreto.decreto.dataCadastro}"
					locale="pt"
					pattern="#{msg.formatoPadraoData}"
					navigator="true"
					mode="popup"
					showOn="button"
					size="15"
					disabled="#{manterDecreto.isDetalhamento}">
				<f:convertDateTime pattern="#{msg.formatoPadraoData}"/>
			    </p:calendar>
			</h:panelGrid>
			<h:panelGrid id="pgDataPublicacao" columns="1">
			    <p:outputLabel for="itDataPublicacao" value="#{msg.decretoDataPublicacao}"/>
			    <p:calendar id="itDataPublicacao"
					value="#{manterDecreto.decreto.dataPublicacao}"
					locale="pt"
					pattern="#{msg.formatoPadraoData}"
					navigator="true"
					mode="popup"
					showOn="button"
					size="15"
					disabled="#{manterDecreto.isDetalhamento}">
				<f:convertDateTime pattern="#{msg.formatoPadraoData}"/>
				<p:ajax event="dateSelect" listener="#{manterDecreto.handleDateSelect}" process="itDataPublicacao, pgTipo, pgDataVencimento" update="pgTipo, pgDataVencimento, otStatus"/>
				<p:ajax event="blur" listener="#{manterDecreto.calcularDataVencimentoDecreto}" process="itDataPublicacao, pgTipo" update="pgDataVencimento, otStatus"/>
			    </p:calendar>			    
			</h:panelGrid>
			<h:panelGrid id="pgTipo" columns="1">
			    <p:outputLabel for="somTipo" value="#{msg.decretoTipo}"/>
			    <p:selectOneMenu id="somTipo" style="width:200px" value="#{manterDecreto.decreto.tipoDecreto}" disabled="#{manterDecreto.isDetalhamento}">
				<f:selectItems value="#{manterDecreto.listaTipos}"/>
				<p:ajax listener="#{manterDecreto.calcularDataVencimentoDecreto}" process="pgTipo" update="pgDataVencimento, otStatus"/>
			    </p:selectOneMenu>
			</h:panelGrid>
			<h:panelGrid id="pgDataVencimento" columns="1">
			    <p:outputLabel for="itDataVencimento" value="#{msg.decretoDataVencimento}"/>
			    <p:inputMask mask="#{msg.mascaraPadraoData}" id="itDataVencimento" value="#{manterDecreto.decreto.dataCaducacao}" readonly="true" size="20" disabled="true" style="color: #000000" required="true" requiredMessage="#{msg.decretoDataVencimento}: #{msg.campo_obrigatorio}">
				<f:convertDateTime pattern="#{msg.formatoPadraoData}"/>
			    </p:inputMask>
			</h:panelGrid>
			<h:panelGrid columns="1">
			    <p:outputLabel for="otStatus" value="#{msg.decretoStatus}"/>
			    <p:inputText id="otStatus" value="#{manterDecreto.statusDecreto.label}" readonly="true" disabled="true" size="33"/>
			</h:panelGrid>
		    </h:panelGrid>
		    <h:panelGrid columns="1">
			<p:outputLabel for="itEmenta" value="#{msg.decretoEmenta}"/>
			<p:inputText id="itEmenta" value="#{manterDecreto.decreto.ementa}" size="186" required="true" requiredMessage="#{msg.decretoEmenta}: #{msg.campo_obrigatorio}" disabled="#{manterDecreto.isDetalhamento}"/>
		    </h:panelGrid>
		    <p:outputPanel rendered="#{manterDecreto.decreto.id != null}">
			<table width="100%">
			    <tr>
				<td width="50%">
				    <h:panelGroup id="pgDadosReratificacao">
					<p:selectBooleanCheckbox id="sbcReratificar" value="#{manterDecreto.reRatificar}" disabled="#{manterDecreto.isDetalhamento}">
					    <p:ajax event="change" listener="#{manterDecreto.limparDecretosReratificados}" process="@this, sbcReratificar" immediate="true" update="opReratificacao"/>
					</p:selectBooleanCheckbox>
					<p:outputLabel for="sbcReratificar" value="#{msg.decretoReRatificar}"/>
				    </h:panelGroup>
				</td>
				<td width="50%">
				    <h:panelGroup id="pgDadosRevogacao">
					<p:selectBooleanCheckbox id="sbcRevogar" value="#{manterDecreto.revogar}" disabled="#{manterDecreto.isDetalhamento}">
					    <p:ajax event="change" listener="#{manterDecreto.limparDecretoRevogado}" process="sbcRevogar, pgDadosRevogacao, otStatus" immediate="true" update="opRevogar, pgDadosRevogacao, otStatus"/>
					</p:selectBooleanCheckbox>
					<p:outputLabel for="sbcRevogar" value="#{msg.decretoRevogar}"/>
				    </h:panelGroup>
				</td>
			    </tr>
			    <tr>
				<td width="50%">
				    <p:outputPanel id="opReratificacao" autoUpdate="false">
					<p:fieldset id="fsReratificacao" rendered="#{manterDecreto.reRatificar}" style="background: #D1DCE4">
					    <h:panelGrid columns="1" style="width: 100%">
						<p:dataTable id="dtReratificacao" 
							     emptyMessage="Nenhuma Reratificação Adicionada"
							     value="#{manterDecreto.reratificacoes}"
							     var="reRat">
						    <p:column headerText="#{msg.decretoData}">
							<h:outputText value="#{reRat.decretoReratificado.dataPublicacao}">
							    <f:convertDateTime pattern="#{msg.formatoPadraoData}"/>
							</h:outputText>
						    </p:column>
						    <p:column headerText="#{msg.decretoDOM}">
							<h:outputLink target="about:blank" value="#{reRat.decretoReratificado.enderecoDom}" disabled="#{manterDecreto.isDetalhamento}">  
							    <h:outputText value="#{reRat.decretoReratificado.enderecoDom30}" title="#{reRat.decretoReratificado.enderecoDom}"/>  
							</h:outputLink> 
						    </p:column>
						    <p:column headerText="#{msg.decretoNum}" style="text-align: center">
							#{reRat.decretoReratificado.numero}
						    </p:column>
						    <p:column headerText="#{msg.acoes}" style="text-align: center" disabledSelection="#{manterDecreto.isDetalhamento}" >
							<p:commandButton icon="ui-icon-close" title="Remover" disabled="#{manterDecreto.isDetalhamento}" oncomplete="pnConfirmaRemocaoReratificacao.show();">
							    <f:setPropertyActionListener value="#{reRat}" target="#{manterDecreto.reratificacaoRemovida}"/>
							</p:commandButton>
						    </p:column>
						</p:dataTable>
						<h:panelGrid id="pgReratificar" columns="3">
						    <p:outputLabel for="acReratificar" value="#{msg.adicionar}: " />
						    <p:autoComplete id="acReratificar" 
								    completeMethod="#{manterDecreto.filtrarDecretos}"
								    var="decreto"
								    itemValue="#{decreto}"
								    itemLabel="#{decreto.numero}"
								    converter="#{decretoConverter}"
								    size="70"
								    autocomplete="true"
								    forceSelection="true"
								    scrollHeight="100"
								    disabled="#{manterDecreto.isDetalhamento}">
							<p:ajax event="itemSelect" listener="#{manterDecreto.selecionarDecreto}" process="acReratificar" update="dtReratificacao" immediate="true"/>
						    </p:autoComplete>						    
						</h:panelGrid>
					    </h:panelGrid>
					</p:fieldset>
				    </p:outputPanel>
				</td>
				<td width="50%" valign="top">
				    <p:outputPanel id="opRevogar">
					<p:fieldset rendered="#{manterDecreto.revogar}" style="background: #D1DCE4">
					    <h:panelGrid id="dadosRevogacao" columns="1" >
						<h:panelGrid columns="1">
						    <p:outputLabel for="acRevogar" value="#{msg.decretoNumero}"/>
						    <p:autoComplete id="acRevogar" 
								    completeMethod="#{manterDecreto.filtrarDecretos}"
								    var="decreto"
								    value="#{manterDecreto.decreto.decretoRevogado}"
								    itemValue="#{decreto}"
								    itemLabel="#{decreto.numero}"
								    converter="#{decretoConverter}"
								    size="83"
								    autocomplete="true"
								    forceSelection="true"
								    scrollHeight="100"
								    disabled="#{manterDecreto.isDetalhamento}">
							<p:ajax event="itemSelect" process="acRevogar" update="otStatus" listener="#{manterDecreto.aoSelecionarRevogado}"/>
							<p:ajax event="blur" process="acRevogar" update="otStatus"/>
						    </p:autoComplete>						    
						</h:panelGrid>
					    </h:panelGrid>
					</p:fieldset>
				    </p:outputPanel>
				</td>
			    </tr>
			</table>
		    </p:outputPanel>
		    <h:panelGrid columns="1">
			<p:outputLabel for="itObservacao" value="#{msg.decretoObservacao}"/>
			<p:inputTextarea id="itObservacao" value="#{manterDecreto.decreto.observacao}" rows="5" cols="186" disabled="#{manterDecreto.isDetalhamento}"/>
		    </h:panelGrid>
		    <h:panelGrid id="pgDOM" columns="1">
			<p:outputLabel for="itDOM" value="#{msg.decretoEnderecoDOM}"/>
			<h:panelGroup>
			    <p:inputText id="itDOM" 
					 value="#{manterDecreto.decreto.enderecoDom}" 
					 size="165" 
					 required="true" 
					 requiredMessage="#{msg.decretoEnderecoDOM}: #{msg.campo_obrigatorio}" 
					 disabled="#{manterDecreto.isDetalhamento}"
					 title="#{manterDecreto.decreto.enderecoDom}">
				<p:ajax event="blur" process="itDOM" update="itDOM, link2, btVisualizar" listener="#{manterDecreto.complementarURL}"/>
			    </p:inputText>
			    <p:spacer width="3"/>
			    <p:commandButton id="btVisualizar" value="#{msg.decretoVisualizar}" disabled="#{manterDecreto.isDetalhamento or manterDecreto.decreto.enderecoDom == null}" onclick="document.getElementById('fManterDecreto:link2').click();" immediate="true"/>
			    <h:outputLink id="link2" target="about:blank" value="#{manterDecreto.decreto.enderecoDom}"/>
			</h:panelGroup>
		    </h:panelGrid>
		</p:fieldset>

		<div class="espacamento"/>

		<p:commandButton value="#{msg.novo}" 
				 icon="ui-icon-plusthick" 
				 ajax="false"
				 immediate="true"
				 rendered="#{manterDecreto.isDetalhamento}"
				 action="#{manterDecreto.setup()}"/>
		<p:spacer width="5" rendered="#{manterDecreto.isDetalhamento}"/>
		<p:commandButton value="#{msg.editar}" 
				 icon="ui-icon-clipboard" 
				 ajax="false"
				 immediate="true"
				 rendered="#{manterDecreto.isDetalhamento}">
		    <f:setPropertyActionListener value="false" target="#{manterDecreto.isDetalhamento}"/>
		</p:commandButton>
		<p:spacer width="5" rendered="#{manterDecreto.isDetalhamento}"/>
		<p:commandButton value="#{msg.salvar}" 
				 icon="ui-icon-disk" 
				 ajax="false"
				 rendered="#{!manterDecreto.isDetalhamento}"
				 action="#{manterDecreto.salvar}"/>
		<p:spacer width="5" rendered="#{!manterDecreto.isDetalhamento}"/>
		<p:commandButton value="#{msg.cancelar}" 
				 icon="ui-icon-closethick"
				 immediate="true"
				 rendered="#{!manterDecreto.isDetalhamento}"
				 onclick="pnConfirmacao.show();">
		    <f:setPropertyActionListener value="#{manterDecreto.decreto.id}" target="#{manterDecreto.idDecretoSelecionado}"/>
		</p:commandButton>	
		<p:spacer width="5" rendered="#{!manterDecreto.isDetalhamento}"/>
		<p:commandButton value="#{msg.voltar}" 
				 action="#{manterDecreto.voltar}" 
				 icon="ui-icon-arrowreturnthick-1-w"
				 ajax="false"
				 immediate="true"/>
		
	    </h:form>

	    <ui:include src="/restrito/painel_confirmacao.xhtml">
		<ui:param name="id" value="pnConfirmaRemocaoReratificacao"/>
		<ui:param name="mensagem" value="#{msg.deseja_remover}"/>
		<ui:param name="bean" value="#{manterDecreto}"/>
		<ui:param name="action" value="removerReratificacao"/>
	    </ui:include>		
	    
	    <ui:include src="/restrito/painel_confirmacao_2.xhtml">
		<ui:param name="id" value="pnLimparReratificacoes"/>
		<ui:param name="mensagem" value="#{msg.decretoDesejaRealmenteLimparDecretosReratificados}"/>
		<ui:param name="bean" value="#{manterDecreto}"/>
		<ui:param name="actionConfirm" value="limparReratificados"/>
		<ui:param name="actionClose" value="configurarReratificar"/>
	    </ui:include>		
	    
	    <ui:include src="/restrito/painel_confirmacao_2.xhtml">
		<ui:param name="id" value="pnLimparDecretoRevogado"/>
		<ui:param name="mensagem" value="#{msg.decretoDesejaRealmenteLimparDecretoRevogado}"/>
		<ui:param name="bean" value="#{manterDecreto}"/>
		<ui:param name="actionConfirm" value="limparRevogado"/>
		<ui:param name="actionClose" value="configurarRevogar"/>
	    </ui:include>		
	    
	    <ui:include src="/restrito/painel_confirmacao.xhtml">
		<ui:param name="id" value="pnConfirmacao"/>
		<ui:param name="mensagem" value="#{msg.deseja_cancelar_operacao}"/>
		<ui:param name="bean" value="#{manterDecreto}"/>
		<ui:param name="action" value="#{manterDecreto.decreto.id != null ? 'detalhar' : 'setup'}"/>
	    </ui:include>

	</ui:define>

    </ui:composition>

</html>
